```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>MyBatis 接口与XML绑定机制详解</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            color: #333;
            line-height: 1.6;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
        }
        .code-block {
            background-color: #282c34;
            border-radius: 8px;
            position: relative;
        }
        .code-header {
            background-color: rgba(255, 255, 255, 0.1);
            padding: 0.5rem 1rem;
            border-top-left-radius: 8px;
            border-top-right-radius: 8px;
            display: flex;
            align-items: center;
        }
        .code-dots {
            display: flex;
            gap: 6px;
        }
        .code-dot {
            width: 12px;
            height: 12px;
            border-radius: 50%;
        }
        .code-title {
            margin-left: 1rem;
            font-size: 0.875rem;
            color: rgba(255, 255, 255, 0.7);
        }
        .drop-cap:first-letter {
            float: left;
            font-size: 4.5em;
            line-height: 0.8;
            margin: 0.15em 0.1em 0 0;
            color: #4f46e5;
            font-weight: 700;
        }
        .hover-scale {
            transition: transform 0.3s ease;
        }
        .hover-scale:hover {
            transform: translateY(-4px);
        }
        .mermaid-tooltip {
            position: absolute;
            background: white;
            padding: 8px;
            border-radius: 4px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
            z-index: 100;
            display: none;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <div class="hero-gradient text-white py-20 px-4 sm:px-6 lg:px-8">
        <div class="max-w-4xl mx-auto text-center">
            <div class="flex justify-center mb-6">
                <div class="bg-white bg-opacity-20 rounded-full p-3">
                    <i class="fas fa-database text-3xl"></i>
                </div>
            </div>
            <h1 class="text-4xl md:text-5xl font-bold mb-6 font-serif">MyBatis 接口与XML绑定机制</h1>
            <p class="text-xl md:text-2xl font-light mb-8 max-w-3xl mx-auto leading-relaxed">
                深入解析Java持久层框架的核心特性与实现原理
            </p>
            <div class="flex justify-center space-x-4">
                <a href="#intro" class="px-6 py-3 bg-white text-indigo-700 font-medium rounded-full hover:bg-opacity-90 transition duration-300 transform hover:-translate-y-1 shadow-lg">
                    开始探索 <i class="fas fa-arrow-down ml-2"></i>
                </a>
            </div>
        </div>
    </div>

    <!-- Main Content -->
    <div class="max-w-4xl mx-auto px-4 sm:px-6 lg:px-8 py-16">
        <!-- Introduction -->
        <section id="intro" class="mb-20">
            <div class="bg-white rounded-xl shadow-lg overflow-hidden hover-scale">
                <div class="p-8">
                    <div class="flex items-center mb-6">
                        <div class="w-12 h-12 bg-indigo-100 rounded-full flex items-center justify-center mr-4">
                            <i class="fas fa-info-circle text-indigo-600 text-xl"></i>
                        </div>
                        <h2 class="text-2xl font-bold text-gray-800">MyBatis 简介</h2>
                    </div>
                    <div class="prose max-w-none drop-cap">
                        <p>MyBatis 是一个优秀的持久层框架，通过简化与数据库的交互，使开发人员可以更加高效地进行数据持久化操作。MyBatis 的一个显著特性就是通过 XML 文件与 Java 接口进行绑定，从而实现 SQL 语句的灵活管理和调用。</p>
                        <p>在 MyBatis 中，XML 文件主要用于定义 SQL 语句、结果映射、参数映射等。Java 接口则用于定义与数据库交互的方法。在运行时，MyBatis 会通过配置文件将这些 SQL 语句与 Java 接口的方法进行绑定，从而实现数据访问。</p>
                    </div>
                </div>
            </div>
        </section>

        <!-- Binding Steps -->
        <section class="mb-20">
            <div class="bg-white rounded-xl shadow-lg overflow-hidden hover-scale">
                <div class="p-8">
                    <div class="flex items-center mb-6">
                        <div class="w-12 h-12 bg-purple-100 rounded-full flex items-center justify-center mr-4">
                            <i class="fas fa-list-ol text-purple-600 text-xl"></i>
                        </div>
                        <h2 class="text-2xl font-bold text-gray-800">XML 文件与接口绑定的基本步骤</h2>
                    </div>
                    <div class="space-y-6">
                        <div class="flex items-start">
                            <div class="flex-shrink-0 bg-indigo-100 text-indigo-700 font-bold rounded-full w-8 h-8 flex items-center justify-center mr-4 mt-1">
                                1
                            </div>
                            <div>
                                <h3 class="text-lg font-semibold mb-2">定义 Mapper 接口</h3>
                                <p class="text-gray-700">每个 Mapper 接口对应一个 XML 映射文件。接口方法名称与 XML 中的 SQL 语句 ID 一一对应。</p>
                            </div>
                        </div>
                        <div class="flex items-start">
                            <div class="flex-shrink-0 bg-indigo-100 text-indigo-700 font-bold rounded-full w-8 h-8 flex items-center justify-center mr-4 mt-1">
                                2
                            </div>
                            <div>
                                <h3 class="text-lg font-semibold mb-2">编写 XML 映射文件</h3>
                                <p class="text-gray-700">XML 文件通常与 Mapper 接口位于同一个包中，文件名与接口名一致。在 XML 中定义 SQL 语句，使用 <code class="bg-gray-100 px-2 py-1 rounded">&lt;select&gt;</code>, <code class="bg-gray-100 px-2 py-1 rounded">&lt;insert&gt;</code>, <code class="bg-gray-100 px-2 py-1 rounded">&lt;update&gt;</code>, <code class="bg-gray-100 px-2 py-1 rounded">&lt;delete&gt;</code> 等标签。</p>
                            </div>
                        </div>
                        <div class="flex items-start">
                            <div class="flex-shrink-0 bg-indigo-100 text-indigo-700 font-bold rounded-full w-8 h-8 flex items-center justify-center mr-4 mt-1">
                                3
                            </div>
                            <div>
                                <h3 class="text-lg font-semibold mb-2">配置 MyBatis 环境</h3>
                                <p class="text-gray-700">在 MyBatis 的全局配置文件中注册 Mapper 接口，或者在运行时通过编程方式进行注册。使用 <code class="bg-gray-100 px-2 py-1 rounded">SqlSession</code> 获取 Mapper 接口的实例。</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Implementation Details -->
        <section class="mb-20">
            <div class="bg-white rounded-xl shadow-lg overflow-hidden hover-scale">
                <div class="p-8">
                    <div class="flex items-center mb-6">
                        <div class="w-12 h-12 bg-blue-100 rounded-full flex items-center justify-center mr-4">
                            <i class="fas fa-code text-blue-600 text-xl"></i>
                        </div>
                        <h2 class="text-2xl font-bold text-gray-800">XML 文件与接口绑定的实现细节</h2>
                    </div>
                    
                    <!-- Mapper Interface -->
                    <div class="mb-10">
                        <h3 class="text-xl font-semibold mb-4 flex items-center">
                            <i class="fas fa-brackets-curly text-indigo-500 mr-2"></i>
                            <span>1. Mapper 接口定义</span>
                        </h3>
                        <p class="text-gray-700 mb-4">Mapper 接口是 MyBatis 的核心组件之一，用于定义与数据库的交互方法。接口中的每个方法代表一个数据库操作。</p>
                        <div class="code-block mb-6">
                            <div class="code-header">
                                <div class="code-dots">
                                    <div class="code-dot bg-red-500"></div>
                                    <div class="code-dot bg-yellow-500"></div>
                                    <div class="code-dot bg-green-500"></div>
                                </div>
                                <div class="code-title">UserMapper.java</div>
                            </div>
                            <pre class="p-4 text-gray-300 overflow-x-auto">
<code class="language-java">package com.ts.mapper;

import com.ts.domain.User;
import org.apache.ibatis.annotations.Param;

public interface UserMapper {
    User getUserById(@Param("id") int id);

    void insertUser(User user);
}</code></pre>
                        </div>
                    </div>
                    
                    <!-- XML Mapping File -->
                    <div class="mb-10">
                        <h3 class="text-xl font-semibold mb-4 flex items-center">
                            <i class="fas fa-file-code text-indigo-500 mr-2"></i>
                            <span>2. XML 映射文件</span>
                        </h3>
                        <p class="text-gray-700 mb-4">XML 映射文件用于定义与 Mapper 接口中方法相对应的 SQL 语句。文件名通常与接口名一致，并放置在相同的包结构中。</p>
                        <div class="code-block mb-6">
                            <div class="code-header">
                                <div class="code-dots">
                                    <div class="code-dot bg-red-500"></div>
                                    <div class="code-dot bg-yellow-500"></div>
                                    <div class="code-dot bg-green-500"></div>
                                </div>
                                <div class="code-title">UserMapper.xml</div>
                            </div>
                            <pre class="p-4 text-gray-300 overflow-x-auto">
<code class="language-xml">&lt;?xml version="1.0" encoding="UTF-8" ?&gt;
&lt;!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"&gt;
&lt;mapper namespace="com.ts.mapper.UserMapper"&gt;
  
    &lt;select id="getUserById" parameterType="int" resultType="com.ts.domain.User"&gt;
        SELECT * FROM users WHERE id = #{id}
    &lt;/select&gt;

    &lt;insert id="insertUser" parameterType="com.ts.domain.User"&gt;
        INSERT INTO users (name, email) VALUES (#{name}, #{email})
    &lt;/insert&gt;
&lt;/mapper&gt;</code></pre>
                        </div>
                    </div>
                    
                    <!-- MyBatis Config -->
                    <div class="mb-10">
                        <h3 class="text-xl font-semibold mb-4 flex items-center">
                            <i class="fas fa-cog text-indigo-500 mr-2"></i>
                            <span>3. MyBatis 配置文件</span>
                        </h3>
                        <p class="text-gray-700 mb-4">MyBatis 的全局配置文件用于配置数据源、事务管理器、Mapper 映射等。可以在其中注册 Mapper 接口。</p>
                        <div class="code-block">
                            <div class="code-header">
                                <div class="code-dots">
                                    <div class="code-dot bg-red-500"></div>
                                    <div class="code-dot bg-yellow-500"></div>
                                    <div class="code-dot bg-green-500"></div>
                                </div>
                                <div class="code-title">mybatis-config.xml</div>
                            </div>
                            <pre class="p-4 text-gray-300 overflow-x-auto">
<code class="language-xml">&lt;?xml version="1.0" encoding="UTF-8" ?&gt;
&lt;!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"&gt;
&lt;configuration&gt;
  
    &lt;environments default="development"&gt;
        &lt;environment id="development"&gt;
            &lt;transactionManager type="JDBC"/&gt;
            &lt;dataSource type="POOLED"&gt;
                &lt;property name="driver" value="com.mysql.cj.jdbc.Driver"/&gt;
                &lt;property name="url" value="jdbc:mysql://localhost:3306/mydb"/&gt;
                &lt;property name="username" value="root"/&gt;
                &lt;property name="password" value="root"/&gt;
            &lt;/dataSource&gt;
        &lt;/environment&gt;
    &lt;/environments&gt;
  
    &lt;mappers&gt;
        &lt;mapper resource="com/ts/mapper/UserMapper.xml"/&gt;
    &lt;/mappers&gt;

&lt;/configuration&gt;</code></pre>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Binding Details -->
        <section class="mb-20">
            <div class="bg-white rounded-xl shadow-lg overflow-hidden hover-scale">
                <div class="p-8">
                    <div class="flex items-center mb-6">
                        <div class="w-12 h-12 bg-green-100 rounded-full flex items-center justify-center mr-4">
                            <i class="fas fa-search-plus text-green-600 text-xl"></i>
                        </div>
                        <h2 class="text-2xl font-bold text-gray-800">XML 文件与接口绑定的细节</h2>
                    </div>
                    <div class="grid md:grid-cols-2 gap-8">
                        <div class="bg-indigo-50 p-6 rounded-lg">
                            <h3 class="text-lg font-semibold mb-3 text-indigo-700 flex items-center">
                                <i class="fas fa-tags mr-2"></i>
                                命名空间（Namespace）
                            </h3>
                            <p class="text-gray-700">XML 映射文件中的 <code class="bg-indigo-100 text-indigo-700 px-2 py-1 rounded">namespace</code> 属性指定了与哪个 Mapper 接口相关联。MyBatis 使用命名空间来区分不同的接口，确保 SQL 语句的唯一性。</p>
                        </div>
                        <div class="bg-purple-50 p-6 rounded-lg">
                            <h3 class="text-lg font-semibold mb-3 text-purple-700 flex items-center">
                                <i class="fas fa-link mr-2"></i>
                                方法与 SQL 语句的绑定
                            </h3>
                            <p class="text-gray-700">在 XML 中定义的 SQL 语句 ID 必须与 Mapper 接口中的方法名一致。参数类型（<code class="bg-purple-100 text-purple-700 px-2 py-1 rounded">parameterType</code>）和返回类型（<code class="bg-purple-100 text-purple-700 px-2 py-1 rounded">resultType</code>）应与接口方法的签名相匹配。</p>
                        </div>
                        <div class="bg-blue-50 p-6 rounded-lg">
                            <h3 class="text-lg font-semibold mb-3 text-blue-700 flex items-center">
                                <i class="fas fa-exchange-alt mr-2"></i>
                                参数传递
                            </h3>
                            <p class="text-gray-700">MyBatis 支持通过注解 <code class="bg-blue-100 text-blue-700 px-2 py-1 rounded">@Param</code> 来指定方法参数名称，以在 XML 中引用。使用 <code class="bg-blue-100 text-blue-700 px-2 py-1 rounded">#{paramName}</code> 语法在 SQL 语句中引用参数。</p>
                        </div>
                        <div class="bg-teal-50 p-6 rounded-lg">
                            <h3 class="text-lg font-semibold mb-3 text-teal-700 flex items-center">
                                <i class="fas fa-cogs mr-2"></i>
                                自动生成实现类
                            </h3>
                            <p class="text-gray-700">MyBatis 在运行时为每个 Mapper 接口生成一个代理实现类，该类负责实际的 SQL 执行。通过 <code class="bg-teal-100 text-teal-700 px-2 py-1 rounded">SqlSession.getMapper(UserMapper.class)</code> 获取接口的代理实现。</p>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Advantages -->
        <section class="mb-20">
            <div class="bg-white rounded-xl shadow-lg overflow-hidden hover-scale">
                <div class="p-8">
                    <div class="flex items-center mb-6">
                        <div class="w-12 h-12 bg-yellow-100 rounded-full flex items-center justify-center mr-4">
                            <i class="fas fa-star text-yellow-600 text-xl"></i>
                        </div>
                        <h2 class="text-2xl font-bold text-gray-800">MyBatis XML 与接口绑定的优点</h2>
                    </div>
                    <div class="grid md:grid-cols-3 gap-6">
                        <div class="bg-white border border-gray-200 rounded-lg p-6 hover:border-indigo-400 transition duration-300">
                            <div class="text-indigo-500 text-4xl mb-4">
                                <i class="fas fa-unlink"></i>
                            </div>
                            <h3 class="text-xl font-semibold mb-3">解耦性</h3>
                            <p class="text-gray-700">将 SQL 语句与 Java 代码分离，提高代码的可维护性和可读性。</p>
                        </div>
                        <div class="bg-white border border-gray-200 rounded-lg p-6 hover:border-purple-400 transition duration-300">
                            <div class="text-purple-500 text-4xl mb-4">
                                <i class="fas fa-sliders-h"></i>
                            </div>
                            <h3 class="text-xl font-semibold mb-3">灵活性</h3>
                            <p class="text-gray-700">开发人员可以通过修改 XML 文件而无需更改 Java 代码来优化或调整 SQL 语句。</p>
                        </div>
                        <div class="bg-white border border-gray-200 rounded-lg p-6 hover:border-blue-400 transition duration-300">
                            <div class="text-blue-500 text-4xl mb-4">
                                <i class="fas fa-expand"></i>
                            </div>
                            <h3 class="text-xl font-semibold mb-3">可扩展性</h3>
                            <p class="text-gray-700">支持复杂的 SQL 构建和动态 SQL，使得 MyBatis 能够满足各种复杂的数据访问需求。</p>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Visualization -->
        <section class="mb-20">
            <div class="bg-white rounded-xl shadow-lg overflow-hidden hover-scale">
                <div class="p-8">
                    <div class="flex items-center mb-6">
                        <div class="w-12 h-12 bg-red-100 rounded-full flex items-center justify-center mr-4">
                            <i class="fas fa-project-diagram text-red-600 text-xl"></i>
                        </div>
                        <h2 class="text-2xl font-bold text-gray-800">MyBatis 工作原理可视化</h2>
                    </div>
                    <div class="bg-gray-50 rounded-lg p-6">
                        <div class="mermaid">
                            graph LR
                                A[Java Application] -->|调用| B[Mapper Interface]
                                B -->|动态代理| C[MyBatis Framework]
                                C -->|执行| D[XML Mapper]
                                D -->|返回结果| C
                                C -->|返回结果| B
                                B -->|返回结果| A
                                E[Database] -->|数据| D
                                D -->|SQL| E
                        </div>
                        <div class="mt-4 text-sm text-gray-600">
                            <p>鼠标悬停在图表元素上可查看详细说明</p>
                        </div>
                    </div>
                </div>
            </div>
        </section>
    </div>

    <!-- Footer -->
    <footer class="bg-gray-900 text-gray-300 py-12 px-4 sm:px-6 lg:px-8">
        <div class="max-w-4xl mx-auto">
            <div class="text-center">
                <h3 class="text-xl font-bold mb-2">技术小馆</h3>
                <p class="mb-6">深入技术细节，探索架构之美</p>
                <div class="flex justify-center space-x-4">
                    <a href="http://www.yuque.com/jtostring" class="text-indigo-400 hover:text-white transition duration-300">
                        <i class="fas fa-globe text-lg"></i>
                        <span class="ml-2">技术小馆地址</span>
                    </a>
                </div>
            </div>
            <div class="mt-8 pt-8 border-t border-gray-800 text-center text-sm">
                <p>© 2023 技术小馆. 保留所有权利.</p>
            </div>
        </div>
    </footer>

    <script>
        // Initialize Mermaid
        mermaid.initialize({
            startOnLoad: true,
            theme: 'dark',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            }
        });
        
        // Smooth scrolling for anchor links
        document.querySelectorAll('a[href^="#"]').forEach(anchor => {
            anchor.addEventListener('click', function (e) {
                e.preventDefault();
                document.querySelector(this.getAttribute('href')).scrollIntoView({
                    behavior: 'smooth'
                });
            });
        });
        
        // Add hover effect for mermaid nodes
        document.addEventListener('DOMContentLoaded', function() {
            setTimeout(() => {
                const mermaidNodes = document.querySelectorAll('.mermaid .node rect, .mermaid .node circle');
                const tooltip = document.createElement('div');
                tooltip.className = 'mermaid-tooltip';
                document.body.appendChild(tooltip);
                
                mermaidNodes.forEach(node => {
                    const text = node.parentNode.querySelector('text')?.textContent || '';
                    let tooltipText = '';
                    
                    if (text.includes('Java Application')) {
                        tooltipText = '应用程序入口，调用Mapper接口方法';
                    } else if (text.includes('Mapper Interface')) {
                        tooltipText = '定义数据库操作的Java接口';
                    } else if (text.includes('MyBatis Framework')) {
                        tooltipText = '核心框架，处理动态代理和SQL执行';
                    } else if (text.includes('XML Mapper')) {
                        tooltipText = '包含SQL语句和映射定义的XML文件';
                    } else if (text.includes('Database')) {
                        tooltipText = '存储数据的数据库系统';
                    }
                    
                    node.addEventListener('mouseenter', (e) => {
                        tooltip.textContent = tooltipText;
                        tooltip.style.display = 'block';
                        tooltip.style.top = `${e.pageY + 15}px`;
                        tooltip.style.left = `${e.pageX + 15}px`;
                    });
                    
                    node.addEventListener('mouseleave', () => {
                        tooltip.style.display = 'none';
                    });
                    
                    node.addEventListener('mousemove', (e) => {
                        tooltip.style.top = `${e.pageY + 15}px`;
                        tooltip.style.left = `${e.pageX + 15}px`;
                    });
                });
            }, 1000);
        });
    </script>
</body>
</html>
```